package com.example.yifei.ui.page.main.purchase.tab.item

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import coil.annotation.ExperimentalCoilApi
import coil.compose.LocalImageLoader
import coil.compose.rememberImagePainter
import com.example.yifei.ui.page.common.RouteName
import com.example.yifei.ui.page.main.purchase.tab.DemandBean
import com.example.yifei.ui.page.widgets.MyButton
import com.example.yifei.utils.RouteUtils
import com.example.yifei.utils.StringUtils
import com.example.yifei.utils.showToast

/**
 * @Author: ZhuDaiHao
 * @Date: 2022/5/13
 * @Describe:
 */

@ExperimentalCoilApi
@ExperimentalMaterialApi
@Composable
fun PurchaseItem(it: DemandBean?, navCtrl: NavHostController) {
    Column(
        modifier = Modifier
            .padding(top = 10.dp, bottom = 10.dp)
            .clickable {
                RouteUtils.navTo(navCtrl = navCtrl, RouteName.PURCHASE_DETAILS)
            }
    ) {

        Column(
            modifier = Modifier.background(
                shape = RoundedCornerShape(4.dp),
                color = Color.White
            )
        ) {

            Row(
                horizontalArrangement = Arrangement.SpaceBetween,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier
                    .padding(
                        start = 17.dp,
                        end = 16.dp,
                        top = 16.dp,
                        bottom = 12.dp
                    )
                    .fillMaxWidth()
            ) {

                Text(
                    text = StringUtils.getEmptyStr(it?.code),
                    fontSize = 14.sp,
                    color = Color(0xff8D90A8)
                )


                Text(
                    text = StringUtils.getEmptyStr(it?.state),
                    fontSize = 14.sp,
                    color = Color(0xffFF9D48)
                )

            }

            Divider(color = Color(0xffF0F0F0), thickness = 0.5.dp)

            Row(
                modifier = Modifier
                    .padding(start = 16.dp, top = 16.dp)
                    .fillMaxWidth(),
            ) {
                Image(painter = rememberImagePainter(
                    data = StringUtils.getEmptyStr(it?.image),
                    imageLoader = LocalImageLoader.current,
                    builder = {
                        placeholder(0)
                    }
                ), contentDescription = "image",
                    contentScale = ContentScale.Crop,
                    modifier = Modifier
                        .size(90.dp)
                        .clip(shape = RoundedCornerShape(4.dp)))


                Column(modifier = Modifier.padding(start = 12.dp)) {
                    Text(
                        text = "供应商：天丰布业",
                        fontSize = 14.sp,
                        color = Color(0xff373C55)
                    )

                    Text(
                        text = "客户款式：1235627828",
                        fontSize = 12.sp,
                        color = Color(0xff8D90A8),
                        modifier = Modifier.padding(bottom = 4.dp, top = 4.dp)
                    )

                    Text(
                        text = "平台款号：SPU999900",
                        fontSize = 12.sp,
                        color = Color(0xff8D90A8),
                    )

                }


            }



            Row(
                horizontalArrangement = Arrangement.End,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier
                    .padding(
                        start = 17.dp,
                        end = 16.dp,
                        top = 12.dp,
                        bottom = 16.dp
                    )
                    .fillMaxWidth()
            ) {
                MyButton(text = "确认提交码单", onClick = {
                    showToast("确认提交码单")
                })

            }

        }
    }
}